<template>
  <div class="shop-details">
    <div class="banner"></div>
    <div class="shop-infos">
      <div class="shop">
        <img :src="query.shop_img" alt="" />
        <div class="infos">
          <div class="title">
            {{ query.shop_name }}
            <!-- <div class="btn">收藏店铺</div> -->
            <el-button class="btn" type="primary" v-if="query.shop_follow"
              >收藏店铺</el-button
            >
            <el-button class="btn" v-else>取消收藏</el-button>
          </div>
          <div class="attention">{{ query.shop_collection }}人关注</div>
          <div class="val">
            <div class="item">
              <span>所有商品</span><b>{{ query.shop_goods }}</b>
            </div>
            <div class="item">
              <span>新品</span><b>{{ query.shop_new }}</b>
            </div>
            <div class="item">
              <span>促销</span><b>{{ query.shop_promotion }}</b>
            </div>
          </div>
        </div>
        <div class="contact">
          <div class="item">
            <div class="tips">商家电话</div>
            <span>{{ query.shop_phone }}</span>
          </div>
          <div class="item">
            <div class="tips">固定电话</div>
            <span>{{ query.fixed_telephone || "--/--" }}</span>
          </div>
          <div class="item">
            <div class="tips">服务时间</div>
            <span>09:00-22:00</span>
          </div>
        </div>
      </div>
      <div class="shop-ss">
        <input type="text" placeholder="请输入关键字" />
        <button>店内搜索</button>
      </div>
    </div>
    <div class="boxs">
      <SwiperList1>
        <div class="class-list" v-if="query.shopcate">
          <div
            @click="selectGoodsClass()"
            class="item"
            :class="{ active: !query.shop_category_id }"
          >
            全部商品
          </div>
          <div
            class="item"
            @click="selectGoodsClass(item.shop_category_id)"
            :class="{
              active: query.shop_category_id === item.shop_category_id,
            }"
            v-for="(item, index) in query.shopcate"
            :key="index"
          >
            {{ item.shop_category_name }}
          </div>
        </div>
      </SwiperList1>
    </div>
    <div class="goods-list" v-if="query.data">
      <GoodsItem7
        :goods="item"
        v-for="(item, index) in query.data"
        :key="index"
      />
    </div>
    <center>
      <Pages1
        @change="getShopInfo"
        :total="false"
        :pages="false"
        :jump="false"
        v-model="query.current"
        :size="query.length"
        :count="query.total"
      />
    </center>
  </div>
</template>

<script>
import api from "@/api";
import GoodsItem7 from "@/components/GoodsItem/GoodsItem7.vue";
import Pages1 from "@/components/Pages/Pages1.vue";
import SwiperList1 from "@/components/SwiperList/SwiperList1.vue";
export default {
  name: "ShopDetails",
  components: { GoodsItem7, Pages1, SwiperList1 },
  data() {
    return {
      query: {
        current: 1,
        length: 10,
        total: 0,
        shop_category_id: "",
      },
    };
  },
  async created() {
    this.query.shop_id = this.$route.params.id;
    this.getShopInfo();
  },
  methods: {
    selectGoodsClass(id) {
      this.query.shop_category_id = id;
      this.query.current = 1;
      this.getShopInfo();
    },
    async getShopInfo() {
      let loading = this.loadingMsg();
      let result = await api.SHOP_INDEX(this.query);
      loading.close();
      this.query = Object.assign(this.query, result);
      this.$forceUpdate();
      window.scrollTo(0, 0);
    },
  },
};
</script>

<style lang="scss" scoped>
.shop-details {
  .banner {
    height: 200px;
    background: #a7211d;
  }
  .shop-infos {
    max-width: 1200px;
    margin: 20px auto;
    display: flex;
    .shop {
      flex: 1;
      width: 0;
      height: 94px;
      padding: 20px;
      background: #ffffff;
      border-radius: 5px;
      display: flex;
      align-items: center;
      margin-right: 20px;
      img {
        width: 94px;
        height: 94px;
        border-radius: 2px;
        margin-right: 21px;
      }
      .infos {
        flex: 1;
        .title {
          font-size: 18px;
          font-weight: 600;
          color: #333333;
          line-height: 25px;
          display: flex;
          align-items: center;
          .btn {
            margin-left: 20px;
            width: 120px;
            height: 28px;
            border-radius: 5px;
            font-size: 14px;
            display: flex;
            justify-content: center;
            align-items: center;
          }
        }
        .attention {
          font-size: 16px;
          font-weight: 400;
          color: #999999;
          margin: 12px 0 13px;
        }
        .val {
          display: flex;
          align-items: center;
          font-size: 16px;
          color: #666666;
          line-height: 22px;
          margin-right: 20px;
          b {
            color: #dc2c1a;
            margin-left: 10px;
            font-weight: 400;
          }
        }
      }
      .contact {
        width: 211px;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .item {
          display: flex;
          align-items: center;
          font-size: 14px;
          color: #666666;
          line-height: 20px;
          justify-content: space-between;
        }
      }
    }
    .shop-ss {
      width: 338px;
      height: 132px;
      background: #ffffff;
      border-radius: 5px;
      border: 1px solid #f0f0f0;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      font-size: 14px;
      input {
        width: 284px;
        padding: 0 12px;
        height: 38px;
        background: #ffffff;
        border-radius: 5px;
        border: 1px solid #f0f0f0;
      }
      button {
        margin-top: 18px;
        width: 308px;
        height: 38px;
        background: #ffffff;
        border-radius: 5px;
        border: 1px solid #d52c1a;
        color: #d52c1a;
      }
    }
  }
  .boxs {
    max-width: 1200px;
    margin: 0 auto 20px;
  }
  .class-list {
    margin: 0 auto 20px;
    .item {
      width: 158px;
      height: 34px;
      cursor: pointer;
      background: #ffffff;
      border: 1px solid #f0f0f0;
      display: inline-flex;
      justify-content: center;
      align-items: center;
      font-size: 14px;
      color: #666666;
      &.active {
        border: 1px solid #d52c1a;
        color: #d52c1a;
      }
    }
  }
  .goods-list {
    max-width: 1200px;
    margin: 0 auto 20px;
    & > div:nth-child(5n + 1) {
      margin-left: 0;
    }
  }
}
</style>
